package cn.javase.base.multithread._05_线程的调度;

public class _03_线程让位 {
    public static void main(String[] args) {
        MyThread thread = new MyThread();
        MyThread thread2 = new MyThread();
        thread.setName("t1");
        thread2.setName("t2");
        thread.start();
        thread2.start();
    }
    private static class MyThread extends Thread {
        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                if (Thread.currentThread().getName().equals("t1") && i % 2 == 0) {
                    System.out.println(Thread.currentThread().getName() + "让位了，下标: " + i);
                    Thread.yield();
                }
                System.out.println(Thread.currentThread().getName() + "==>" + i);
            }
        }
    }
}
